﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

namespace CeA.Reports.Atendimento.Web.WebControls {
    public partial class MenuInterno : System.Web.UI.UserControl {
        [Serializable]
        public class LinkLine {
            private string m_linkName;
            private string m_linkUri;

            public LinkLine(string linkName, string linkUri) {
                m_linkName = linkName;
                m_linkUri = linkUri;
            }

            public string LinkName {
                get { return m_linkName; }
                set { m_linkName = value; }
            }

            public string LinkUri {
                get { return m_linkUri; }
                set { m_linkUri = value; }
            }
        }

        public List<LinkLine> Links {
            get {
                if (ViewState["m_links"] != null) {
                    return (List<LinkLine>)ViewState["m_links"];
                }
                else {
                    List<LinkLine> m_links = new List<LinkLine>();
                    ViewState.Add("m_links", m_links);
                    return (List<LinkLine>)ViewState["m_links"];
                }
            }
        }

        public string Titulo {
            get {
                if (ViewState["m_titulo"] != null)
                    return Convert.ToString(ViewState["m_titulo"]);
                else {
                    return "Sem Titulo";
                }
            }
            set {
                ViewState.Add("m_titulo", value);
            }
        }

        protected void Page_Init(object sender, EventArgs e) {

        }

        protected void Page_Load(object sender, EventArgs e) {
            lblTitle.Text = Titulo;

            List<LinkLine> links = Links;
            for (int i = 0; i < links.Count; i++) {
                LiteralControl lc = new LiteralControl();
                lc.Text = string.Format("<li><a href='{0}'>{1}</a></li>", links[i].LinkUri, links[i].LinkName);
                ulLinks.Controls.Add(lc);
            }
        }

        public void addMenuItem(string name, string uri) {
            if (!Page.IsPostBack)
                Links.Add(new LinkLine(name, uri));

        }
    }
}